package com.ipt.frm.pw.listener;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Application Lifecycle Listener implementation class PropertiesListener
 *
 */
public class PropertiesListener implements ServletContextListener {
	static Properties propertiesMsg;
    static final String PATH_PROPERTIES_MSG = "/WEB-INF/config/messages.properties";
	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent event) {
    	propertiesMsg = new Properties();
    	try {
    		ServletContext sc = event.getServletContext();
			propertiesMsg.load(sc.getResourceAsStream(PATH_PROPERTIES_MSG));
			sc.setAttribute("propertiesMsg", propertiesMsg);
			
    	}catch (IOException e) {
			e.printStackTrace();
		}
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent event) {
    	propertiesMsg = null;
    }
	
}
